
    require("../config.php");
    require('../function/safe.php');
    require("../function/function.php");
    if($_REQUEST["mode"]=="send"){
        $id = hash("sha256", time().$_REQUEST["email"].rand(1,10));
        $text = rand(100000, 999999);
        mysqli_query($con, "INSERT INTO star_php_code (id, text) VALUES ('$id', '$text')");
        sendMail($smtpurl, $smtpemail, $smtpport, $smtpkey, $_REQUEST["email"],'蓝星云PHP框架','验证码','您的验证码是：<p style="color:rad">'.$text.'</p>');
        $return = array('id'=>$id, 'code'=>200);
        echo json_encode($return);
    }elseif($_REQUEST["mode"]=="read"){
        $id = $_REQUEST["id"];
        $text = $_REQUEST["text"];
        $result = mysqli_query($con,"SELECT * FROM star_php_code WHERE id='$id'");
        if($result->numrows ==0){
            $return = array('info'=>"error", 'code'=>404);
            echo json_encode($return);
        }else{
            while($row = mysqli_fetch_array($result)){
                if($row["text"]==$text){
                    $return = array('code'=>200);
                    echo json_encode($return);
                    mysqli_query($con,"DELETE FROM `star_php_code` WHERE `star_php_code`.`id` = '".$_REQUEST["id"]."'");
                }else{
                    $return = array('code'=>400);
                    echo json_encode($return);
                }
            }
        }
    }
?>